<?php
/**
 * putObject，最大可以上传5G的文件。而使用 MultipartUploader 最大可以上传5TB的文件。
 * 当不知道使用哪个方法时，可以直接使用ObjectUploader 对象。它会自动判断
 * author: JiangJun
 * CreateTime:2021/8/30 6:03 下午
 */

use Aws\Exception\MultipartUploadException;
use Aws\S3\MultipartUploader;
use Aws\S3\ObjectUploader;
use Aws\S3\S3Client;

require '../sqs/vendor/autoload.php';

$s3Client = new S3Client([
    'region' => 'ap-northeast-2',
    'version' => '2006-03-01'
]);


$bucket = 'jiang-bucket';
$key = 'test2.zip';

//与objectUploader不同，这里给的是文件路径
$source = './test2.zip';

$uploader = new MultipartUploader($s3Client, $source, [
    'bucket' => $bucket,
    'key' => $key,
]);

try {
    $result = $uploader->upload();
    echo "Upload complete: {$result['ObjectURL']}\n";
} catch (MultipartUploadException $e) {
    echo $e->getMessage() . "\n";
}
